﻿using MediatR;
using NLog.Config;
using W.Purchase.API.Application.Command;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler
{
    public class VendorIsdelAllcommandHandler : IRequestHandler<VendorIsdelAllcommand, int>
    {
        private readonly IVendorRepository vendorRepository;

        public VendorIsdelAllcommandHandler(IVendorRepository vendorRepository)
        {
            this.vendorRepository = vendorRepository;
        }

        public async Task<int> Handle(VendorIsdelAllcommand request, CancellationToken cancellationToken)
        {
            var list = (await vendorRepository.GetAllAsaync()).Where(x => request.Ins.Contains(x.VendorId)).ToList();
            list.ForEach(x =>
            {
                x.IsDelete = true;
                x.DeleteTime = DateTime.Now;
            });
            return await vendorRepository.UpdateRangeAsync(list);
        }
    }
}
